package com.enjoyor.soa.traffic.server.efoms.dubbo.manage;

import com.alibaba.dubbo.config.annotation.Service;
import com.enjoyor.soa.traffic.api.dto.efoms.PingConnectRealDto;
import com.enjoyor.soa.traffic.core.efoms.domain.PingConnectReal;
import com.enjoyor.soa.traffic.core.efoms.service.IPingConnectRealService;
import com.enjoyor.soa.traffic.util.enums.EnumAppCode;
import com.enjoyor.soa.traffic.util.helper.LoggerHelper;
import com.enjoyor.soa.traffic.util.helper.ReflectHelper;
import com.enjoyor.soa.traffic.util.helper.ResultHelper;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class ManagePingConnectRealService {

    @Autowired
    private IPingConnectRealService pingConnectRealService;

    /**
     * 查询网络实时数据
     * @param pingRealId 网络实时编号
     * @param devCategoryCode 设备种类编号
     * @param devTypeCode 设备类型编号
     * @param devId 设备编号
     * @param devName 设备名称
     * @param creatStartTime 记录开始时间
     * @param creatEndTime 记录结束时间
     * @return
     */
	public ResultPojo selectPingConnectRealList(String pingRealId, String devCategoryCode, String devTypeCode,
			String devId, String devName, String creatStartTime, String creatEndTime) {
        try {
			List<PingConnectReal> pingConnectRealList = pingConnectRealService.selectPingConnectRealList(pingRealId,
					devCategoryCode, devTypeCode, devId, devName, creatStartTime, creatEndTime);
			List<PingConnectRealDto> pingConnectRealDtoList = ReflectHelper.listToList(pingConnectRealList,
					PingConnectRealDto.class);
			return ResultHelper.getResult(pingConnectRealDtoList);
        } catch (Exception e) {
            LoggerHelper.LOG.error(e);
            return ResultHelper.getResult(e, EnumAppCode.OPERATOR_FAILURE);
        }
    }
    
    /**
     * 新增网络实时数据
     * @param pingConnectRealDto
     * @param username
     */
    public ResultPojo insertPingConnectReal(PingConnectRealDto pingConnectRealDto, String username) {
        try {
            if (pingConnectRealDto == null)
                return ResultHelper.getResult(EnumAppCode.PARAM_ERR);
            PingConnectReal pingConnectReal = ReflectHelper.beanToBean(pingConnectRealDto, PingConnectReal.class);
            String pingRealId = pingConnectRealService.insertPingConnectReal(pingConnectReal, username);
            return ResultHelper.getResult(pingRealId);
        } catch (Exception e) {
            LoggerHelper.LOG.error(e);
            return ResultHelper.getResult(e, EnumAppCode.OPERATOR_FAILURE);
        }
    }
    
    /**
     * 新增网络实时数据List
     * @param List<PingConnectRealDto>
     * @param username
     */
    public ResultPojo insertPingConnectBatch(List<PingConnectReal> pingConnectRealList, String username) {
        try {
            if (pingConnectRealList == null || pingConnectRealList.size() <= 0) {
            	return ResultHelper.getResult(EnumAppCode.PARAM_ERR);
            }
            String resultId = pingConnectRealService.insertPingConnectBatch(pingConnectRealList, username);
            
            return ResultHelper.getResult(resultId);
        } catch (Exception e) {
            LoggerHelper.LOG.error(e);
            return ResultHelper.getResult(e, EnumAppCode.OPERATOR_FAILURE);
        }
    }

    /**
     * 修改网络实时数据
     * @param pingConnectRealDto
     * @param username
     */
    public ResultPojo updatePingConnectReal(PingConnectRealDto pingConnectRealDto, String username) {
        try {
            if (pingConnectRealDto == null || pingConnectRealDto.getPingRealId() == null || 
            		pingConnectRealDto.getPingRealId().equals(""))
            	return ResultHelper.getResult(EnumAppCode.PARAM_ERR);
            PingConnectReal pingConnectReal = ReflectHelper.beanToBean(pingConnectRealDto, PingConnectReal.class);
            String pingRealId = pingConnectRealService.updatePingConnectReal(pingConnectReal, username);
            return ResultHelper.getResult(pingRealId);
        } catch (Exception e) {
            LoggerHelper.LOG.error(e);
            return ResultHelper.getResult(e, EnumAppCode.OPERATOR_FAILURE);
        }

    }

    /**
     * 删除网络实时数据
     * @param pingRealId
     * @param username
     */
    public ResultPojo deletePingConnectReal(String pingRealId, String username) {
        try {
            if (pingRealId == null || pingRealId.equals(""))
                return ResultHelper.getResult(EnumAppCode.PARAM_ERR);
            pingConnectRealService.deletePingConnectReal(pingRealId, username);
            return ResultHelper.getResult(pingRealId);
        } catch (Exception e) {
            LoggerHelper.LOG.error(e);
            return ResultHelper.getResult(e, EnumAppCode.OPERATOR_FAILURE);
        }
    }
}
